package cn.smbms.controller.inter;

import cn.smbms.pojo.User;
import org.apache.ibatis.plugin.Intercepts;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;


/**
 * Servlet 3大器
 * 过滤器
 * 监听器
 *
 * 拦截器  拦截所有的请求  判断用户是否登陆
 * @author Tequila
 **/

public class PermissionInterceptor extends HandlerInterceptorAdapter {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        User userSession = (User) request.getSession().getAttribute("userSession");
        if (userSession != null){
            return true;

        }
        response.sendRedirect(request.getContextPath()+ "/401.jsp");
        return false;
    }
}
